const path = require('path');
const webpack = require('webpack');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');

module.exports = {
    entry: './src/App.tsx',
    output: {
        path: path.join(__dirname, 'build'),
        filename: "bundle.js",
    },
    resolve: {
        // modules: [
        //     path.join(__dirname, "src"),
        //     "node_modules"
        // ],
        // alias: {
        //     'react': 'react/dist/react.min',
        //     'react-dom': 'react-dom/dist/react-dom.min',
        //     'antd': 'antd/dist/antd.min',
        // },
        extensions: [".webpack.js", ".web.js", ".ts", ".tsx", ".js"]
    },
    module: {
        rules: [{
            test: /\.(css|less)$/,
            include: [
                /src/,
                '/node_modules/antd/' //增加此项
            ],
            use: ['style-loader', {loader: 'css-loader', options: {importLoaders: 1}}, 'less-loader']
        }, {
            test: /\.tsx?$/, loader: "awesome-typescript-loader", exclude: /node_modules/
        }],
        noParse: /moment/,
    },
    externals: {
        lodash: '_',
        'lodash/fp': '_',
        mobx: 'mobx',
        'mobx-react': 'mobxReact',
        axios: 'axios',
        moment: 'moment',
        react: 'React',
        'react-dom': 'ReactDOM',
        'antd': 'antd'
    },
    plugins: [

        new webpack.optimize.ModuleConcatenationPlugin(),
        new webpack.DefinePlugin({
            'process.env': {
                'NODE_ENV': JSON.stringify('production')
            }
        }),
        new UglifyJSPlugin({
            uglifyOptions: {
                compress: true,
                mangle: true
            }
        })
    ]
};